/**
 * Copyright &copy; 2015-2020 <a href="http://www.easyhis.com/">easyhis</a> All rights reserved.
 */
package com.easy.modules.sys.service.impl;

import com.easy.common.util.Utility;
import com.easy.core.persistence.Page;
import com.easy.core.service.impl.BaseServiceImpl;
import com.easy.modules.sys.entity.SystemConfig;
import com.easy.modules.sys.mapper.SystemConfigMapper;
import com.easy.modules.sys.service.SystemConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * 系统配置Service
 * @author liugf
 * @version 2016-02-07
 */
@Service
@Transactional(readOnly = true)
public class SystemConfigServiceImpl  extends BaseServiceImpl implements SystemConfigService {

	@Autowired
	private SystemConfigMapper mapper;

	/**
	 * 获取单条数据
	 * @param id
	 * @return
	 */
	public SystemConfig get(String id) {
		return mapper.get(id);
	}

	/**
	 * 获取单条数据
	 * @param confId
	 * @return
	 */
	public SystemConfig getByConfId(Integer confId) {
		return mapper.getByConfId(confId);
	}

	/**
	 * 获取单条数据
	 * @param systemConfig
	 * @return
	 */
	public SystemConfig get(SystemConfig systemConfig) {
		return mapper.get(systemConfig);
	}

	/**
	 * 查询列表数据
	 * @param systemConfig
	 * @return
	 */
	public List<SystemConfig> findList(SystemConfig systemConfig) {
		dataRuleFilter(systemConfig);
		return mapper.findList(systemConfig);
	}

	/**
	 * 查询分页数据
	 * @param page 分页对象
	 * @param systemConfig
	 * @return
	 */
	public Page<SystemConfig> findPage(Page<SystemConfig> page, SystemConfig systemConfig) {
		dataRuleFilter(systemConfig);
		systemConfig.setPage(page);
		page.setList(mapper.findList(systemConfig));
		return page;
	}

	/**
	 * 保存数据（插入或更新）
	 * @param systemConfig
	 */
	@Transactional(readOnly = false)
	public void save(SystemConfig systemConfig) {
		if (Utility.isNullorEmpty(systemConfig.getId()) || systemConfig.getConfId()<1){
			systemConfig.preInsert();
			mapper.insert(systemConfig);
		}else{
			systemConfig.preUpdate();
			mapper.update(systemConfig);
		}
	}

	/**
	 * 删除数据
	 * @param systemConfig
	 */
	@Transactional(readOnly = false)
	public void delete(SystemConfig systemConfig) {
		mapper.delete(systemConfig);
	}


	/**
	 * 删除全部数据
	 * @param systemConfigs
	 */
	@Transactional(readOnly = false)
	public void deleteAll(Collection<SystemConfig> systemConfigs) {
		for (SystemConfig systemConfig : systemConfigs) {
			mapper.delete(systemConfig);
		}
	}

	/**
	 * 删除全部数据
	 * @param systemConfigs
	 */
	@Transactional(readOnly = false)
	public void deleteAllByLogic(Collection<SystemConfig> systemConfigs) {
		for (SystemConfig systemConfig : systemConfigs) {
			mapper.deleteLogic(systemConfig);
		}
	}


	/**
	 * 获取单条数据
	 * @param propertyName, value
	 * @return
	 */
	public SystemConfig findUniqueByProperty(String propertyName, Object value){
		return mapper.findUniqueByProperty(propertyName, value);
	}

	/**
	 * 动态sql
	 * @param sql
	 */

	public List<Object> executeSelectSql(String sql){
		return mapper.execSelectSql(sql);
	}

	@Transactional(readOnly = false)
	public void executeInsertSql(String sql){
		mapper.execInsertSql(sql);
	}

	@Transactional(readOnly = false)
	public void executeUpdateSql(String sql){
		mapper.execUpdateSql(sql);
	}

	@Transactional(readOnly = false)
	public void executeDeleteSql(String sql){
		mapper.execDeleteSql(sql);
	}


}